#include <bits/stdc++.h>
using namespace std;

const int MAX_OPERATIONS = 200000; // 根据题目描述，最多有 10^5 次操作

struct Operation {
    int type; // 1 for store, 2 for extract
    int i;    // 寄包柜编号
    int j;    // 格子编号
    long long k; // 物品编号（仅在 type 为 1 时有效）
};

Operation operations[MAX_OPERATIONS];
int operation_count = 0;

void store(int i, int j, long long k) {
    operations[operation_count].type = 1;
    operations[operation_count].i = i;
    operations[operation_count].j = j;
    operations[operation_count].k = k;
    operation_count++;
}

void extract(int i, int j) {
    for (int a = operation_count - 1; a >= 0; a--) {
        if (operations[a].type == 1 && operations[a].i == i && operations[a].j == j) {
            cout << operations[a].k << endl;
            return;
        }
    }
    cout << 0 << endl;
}

int main() {
    int n, q;
    cin >> n >> q;
    
    for (int i = 0; i < q; i++) {
        int op;
        cin >> op;
        if (op == 1) {
            int i, j;
            long long k;
            cin >> i >> j >> k;
            store(i, j, k);
        } else if (op == 2) {
            int i, j;
            cin >> i >> j;
            extract(i, j);
        }
    }
    
    return 0;
}